package sqlist;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-10-27
 * Time：13:54
 */

public class TestDemo {
    //去掉第1个字符串中的，所有第2个字符串中的字符
    public static List<Character> func(String s1, String s2) {
        List<Character> ret = new ArrayList<>();
        for (int i = 0; i < s1.length(); i++) {
            if (!s2.contains(s1.charAt(i) + "")) {
                ret.add(s1.charAt(i));
            }
        }
        return ret;
    };

    public static void main(String[] args) {
        List<Character> ret = func("welcome to China", "come");
        System.out.println(ret);
    }
    public static void main7(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0,1);
        arrayList.add(1,2);
        arrayList.add(2,199);
        arrayList.add(3,299);
        arrayList.add(4,399);

        List<Integer> list = arrayList.subList(1,3);//[1,3)
        System.out.println(list);//[2,199]
        System.out.println("================");
        list.set(0, 99999);
        System.out.println(list);
        System.out.println("原来的list"+arrayList);//他也就是说sublist是浅拷贝
    }
    public static void main6(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0,1);
        arrayList.add(1,2);
        arrayList.add(2,99);
        arrayList.add(3,99);
        //arrayList.remove(0);
        //arrayList.remove(new Integer(99));
        arrayList.remove(arrayList.lastIndexOf(99));
        System.out.println(arrayList);

    }
    public static void main5(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        ArrayList<Integer> arrayList2 = new ArrayList<>();
        arrayList2.add(99);
        arrayList2.addAll(arrayList);//传的参数同构造方法
        System.out.println(arrayList2);
    }
    public static void main4(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();//空的数组，大小为0
        arrayList.add(1);//第一次add的时候，底层的数组才变成了10
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        System.out.println(arrayList);
        System.out.println(arrayList.size());
        System.out.println(arrayList.get(1));
        System.out.println("====================");
        //只要是实现Collection接口的类，并且<>内是Integer或其子类，都可以使用下面这个构造方法
        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList);
        arrayList2.add(99);
        System.out.println(arrayList2);

        ArrayList<Integer> arrayList3 = new ArrayList<>(15);
    }
    public static void main3(String[] args) {
        MyArraylist<Integer> myArraylist = new MyArraylist<>();
        myArraylist.add(1);
        myArraylist.add(2);
        myArraylist.add(3);
        myArraylist.add(4);
        myArraylist.add(5);
        myArraylist.remove(3);
        myArraylist.display();
        myArraylist.clear();
        myArraylist.display();
    }
    public static void main2(String[] args) {
        MyArraylist<Integer> myArraylist = new MyArraylist<>();
        myArraylist.add(1);
        myArraylist.add(2);
        myArraylist.add(3);
        myArraylist.add(4);
        myArraylist.add(5);
        System.out.println("5的下标为："+myArraylist.indexOf(5));
        myArraylist.set(3, 40);
        myArraylist.display();
    }
    public static void main1(String[] args) {
        MyArraylist<Integer> myArraylist = new MyArraylist<>();
        myArraylist.add(1);
        myArraylist.add(2);
        myArraylist.add(3);
        myArraylist.add(4);
        myArraylist.add(5);
        myArraylist.add(3, 6);
        myArraylist.display();
        System.out.println("=====================");
        int value = myArraylist.get(4);
        System.out.println(value);

    }
}
